/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

package helloscala.practise.chapter12

import helloscala.practise.ChapterEntry

object Chapter12Entry extends ChapterEntry {
  def runTests: Unit = {
    testBasicReflectionMethods
  }

  def testBasicReflectionMethods = {
    trait T[A] {
      val vT: A
      def mT = vT
    }

    class C extends T[String] {
      val vT = "T"
      val vC = "C"
      def mC = vC
      def this(vTv: String) = {
        this()
      }
      class C2
      trait T2
    }

    val c = new C
    val clazz = c.getClass //java style
    val clazz2 = classOf[C] //scala style, same as .getClass() in java
    val methods = clazz.getMethods
    val ctors = clazz.getConstructors
    val fields = clazz.getFields
    val annos = clazz.getAnnotations
    val name = clazz.getName
    val interfaces = clazz.getInterfaces
    val superClass = clazz.getSuperclass
    val typeParams = clazz.getTypeParameters

    println(clazz)
    println(clazz2)
    println(methods.foreach(m => print(m.getName + ",")));
    println(ctors.foreach(c => print(c.toString + ",")))
    println(fields.foreach(f => print(f + ",")))
    println(annos.foreach(a => print(a + ",")))
    println(name)
    println(interfaces.foreach(i => print(i.getName + ",")))
    println(superClass)
    println(typeParams)
  }
}
